package net.hotelOrderSystem.service;

import net.hotelOrderSystem.domain.Room;
import net.hotelOrderSystem.domain.RoomExample;
import net.hotelOrderSystem.mapper.RoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {

    @Autowired
    private RoomMapper roomMapper;

    @Override
    public List<Room> findRoom() {

        return roomMapper.selectByExample(new RoomExample());
    }

    @Override
    public void saveRoom(Room room) {
        if(room.getRoomNumber() == null) {
            roomMapper.insert(room);
        } else {
            roomMapper.updateByPrimaryKey(room);
        }
    }

    @Override
    public void deleteRoomByRoomNumber( String roomNumber) {
        RoomExample room = new RoomExample();
        room.createCriteria().andRoomNumberEqualTo(roomNumber);
        roomMapper.deleteByExample(room);
    }

    @Override
    public void updateRoomByRoomNumber(String roomNumber, Room room) {
        RoomExample room1 = new RoomExample();
        room1.createCriteria().andRoomNumberEqualTo(roomNumber);
        roomMapper.updateByExample(room,room1);
    }

    @Override
    public Room findRoomByRoomNumber( String roomNumber) {
        RoomExample room = new RoomExample();
        room.createCriteria().andRoomNumberEqualTo(roomNumber);
        return roomMapper.selectByExample(room).get(0);
    }

    @Override
    public List<Room> findRoomByHotelId(String hotelId) {
        RoomExample room = new RoomExample();
        room.createCriteria().andHotelIdEqualTo(hotelId);
        return roomMapper.selectByExample(room);
    }

    @Override
    public void updateRoomStatu(Date inTime, Date outTime, String roomNumber) {

    }

}
